Libraries

library(arules)
## Loading required package: Matrix
## 
## Attaching package: 'arules'
## The following objects are masked from 'package:base':
## 
##     abbreviate, write
library(arulesViz)
library(lsa)
## Loading required package: SnowballC
library(plyr)

Association Analysis

A - Transform to transactions and read

Reading the files

transact1 <- read.transactions("tr-1k-canonical.csv", sep=",")
transact1 <- transact1[-c(1)]
summary(transact1)
## transactions as itemMatrix in sparse format with
##  1000 rows (elements/itemsets/transactions) and
##  57 columns (items) and a density of 0.06178947 
## 
## most frequent items:
## Gongolais Cookie     Truffle Cake     Tuile Cookie       Berry Tart 
##              108              103              102               95 
##    Coffee Eclair          (Other) 
##               93             3021 
## 
## element (itemset/transaction) length distribution:
## sizes
##   1   2   3   4   5   6   7 
##  60 162 338 216 132  44  48 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.000   3.000   3.000   3.522   4.000   7.000 
## 
## includes extended item information - examples:
##   labels
## 1      1
## 2      2
## 3      3
#inspect(transact1[0:5])

transact2 <- read.transactions("tr-5k-canonical.csv", sep=",")
transact2 <- transact2[-c(1)]
summary(transact2)
## transactions as itemMatrix in sparse format with
##  5000 rows (elements/itemsets/transactions) and
##  57 columns (items) and a density of 0.06186667 
## 
## most frequent items:
##    Coffee Eclair       Hot Coffee     Tuile Cookie  Strawberry Cake 
##              554              499              498              480 
## Gongolais Cookie          (Other) 
##              477            15124 
## 
## element (itemset/transaction) length distribution:
## sizes
##    1    2    3    4    5    6    7 
##  248  923 1601 1144  596  237  251 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.000   3.000   3.000   3.526   4.000   7.000 
## 
## includes extended item information - examples:
##   labels
## 1      1
## 2      2
## 3      3
#inspect(transact2[0:5])

transact3 <- read.transactions("tr-20k-canonical.csv", sep=",")
transact3 <- transact3[-c(1)]
summary(transact3)
## transactions as itemMatrix in sparse format with
##  20000 rows (elements/itemsets/transactions) and
##  57 columns (items) and a density of 0.06205 
## 
## most frequent items:
##   Coffee Eclair      Hot Coffee    Tuile Cookie  Apricot Danish Strawberry Cake 
##            2197            2025            1972            1844            1840 
##         (Other) 
##           60859 
## 
## element (itemset/transaction) length distribution:
## sizes
##    1    2    3    4    5    6    7 
##  934 3612 6570 4555 2305 1044  980 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.000   3.000   3.000   3.537   4.000   7.000 
## 
## includes extended item information - examples:
##   labels
## 1      1
## 2      2
## 3      3
#inspect(transact3[0:5])

transact4 <- read.transactions("tr-75k-canonical.csv", sep=",")
transact4 <- transact4[-c(1)]
summary(transact4)
## transactions as itemMatrix in sparse format with
##  75000 rows (elements/itemsets/transactions) and
##  57 columns (items) and a density of 0.06192468 
## 
## most frequent items:
##   Coffee Eclair    Tuile Cookie      Hot Coffee     Cherry Tart Strawberry Cake 
##            8193            7552            7551            6987            6948 
##         (Other) 
##          227497 
## 
## element (itemset/transaction) length distribution:
## sizes
##     1     2     3     4     5     6     7 
##  3592 13579 24674 17003  8640  3840  3672 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    1.00    3.00    3.00    3.53    4.00    7.00 
## 
## includes extended item information - examples:
##   labels
## 1      1
## 2      2
## 3      3
#inspect(transact4[0:5])

B - Applying Apriori

i - Applying Apriori - 1K

#minSup, minConf
paste("Why minSup=0.019, conf=0.94? Because after careful consideration, the rules with the most LIFT values were gained through these. Also, as we did in the written questions, we want rules that have low support but high confidence. ")
## [1] "Why minSup=0.019, conf=0.94? Because after careful consideration, the rules with the most LIFT values were gained through these. Also, as we did in the written questions, we want rules that have low support but high confidence. "
#itemFrequencyPlot(transact1, support = 0.019)

frequent_list1 <- apriori(transact1, parameter=list(support = 0.019, target="frequent itemsets"))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##          NA    0.1    1 none FALSE            TRUE       5   0.019      1
##  maxlen            target  ext
##      10 frequent itemsets TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 19 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[50 item(s), 1000 transaction(s)] done [0.00s].
## sorting and recoding items ... [50 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 4 5 done [0.00s].
## sorting transactions ... done [0.00s].
## writing ... [121 set(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
inspect(sort(frequent_list1, decreasing = T, by="support"))
##       items                 support count
## [1]   {Gongolais Cookie}      0.108   108
## [2]   {Truffle Cake}          0.103   103
## [3]   {Tuile Cookie}          0.102   102
## [4]   {Berry Tart}            0.095    95
## [5]   {Coffee Eclair}         0.093    93
## [6]   {Hot Coffee}            0.093    93
## [7]   {Strawberry Cake}       0.091    91
## [8]   {Marzipan Cookie}       0.090    90
## [9]   {Napoleon Cake}         0.090    90
## [10]  {Apple Croissant}       0.090    90
## [11]  {Lemon Cake}            0.085    85
## [12]  {Chocolate Cake}        0.084    84
## [13]  {Cherry Tart}           0.084    84
## [14]  {Apple Danish}          0.084    84
## [15]  {Raspberry Cookie}      0.082    82
## [16]  {Orange Juice}          0.081    81
## [17]  {Blueberry Tart}        0.081    81
## [18]  {Chocolate Coffee}      0.081    81
## [19]  {Apple Tart}            0.079    79
## [20]  {Opera Cake}            0.078    78
## [21]  {Cheese Croissant}      0.078    78
## [22]  {Bottled Water}         0.076    76
## [23]  {Lemon Tart}            0.076    76
## [24]  {Apricot Croissant}     0.076    76
## [25]  {Apricot Danish}        0.075    75
## [26]  {Cherry Soda}           0.075    75
## [27]  {Blackberry Tart}       0.073    73
## [28]  {Vanilla Frappuccino}   0.072    72
## [29]  {Casino Cake}           0.072    72
## [30]  {Raspberry Lemonade}    0.072    72
## [31]  {Apple Pie}             0.068    68
## [32]  {Lemon Lemonade}        0.066    66
## [33]  {Lemon Cookie}          0.066    66
## [34]  {Almond Twist}          0.064    64
## [35]  {Green Tea}             0.062    62
## [36]  {Walnut Cookie}         0.061    61
## [37]  {Gongolais Cookie,                 
##        Truffle Cake}          0.058    58
## [38]  {Single Espresso}       0.057    57
## [39]  {Apricot Tart}          0.056    56
## [40]  {Blueberry Danish}      0.054    54
## [41]  {Marzipan Cookie,                  
##        Tuile Cookie}          0.053    53
## [42]  {Chocolate Tart}        0.051    51
## [43]  {Almond Croissant}      0.049    49
## [44]  {Napoleon Cake,                    
##        Strawberry Cake}       0.049    49
## [45]  {Vanilla Meringue}      0.047    47
## [46]  {Apricot Danish,                   
##        Cherry Tart}           0.046    46
## [47]  {Chocolate Cake,                   
##        Chocolate Coffee}      0.046    46
## [48]  {Ganache Cookie}        0.044    44
## [49]  {Apple Croissant,                  
##        Apple Tart}            0.044    44
## [50]  {Chocolate Croissant}   0.042    42
## [51]  {Apple Croissant,                  
##        Apple Danish}          0.042    42
## [52]  {Almond Tart}           0.041    41
## [53]  {Cherry Tart,                      
##        Opera Cake}            0.041    41
## [54]  {Apple Danish,                     
##        Apple Tart}            0.041    41
## [55]  {Pecan Tart}            0.040    40
## [56]  {Lemon Cake,                       
##        Lemon Tart}            0.040    40
## [57]  {Casino Cake,                      
##        Chocolate Cake}        0.040    40
## [58]  {Apricot Croissant,                
##        Blueberry Tart}        0.040    40
## [59]  {Apple Croissant,                  
##        Apple Danish,                     
##        Apple Tart}            0.040    40
## [60]  {Apricot Danish,                   
##        Opera Cake}            0.039    39
## [61]  {Chocolate Meringue}    0.038    38
## [62]  {Casino Cake,                      
##        Chocolate Coffee}      0.038    38
## [63]  {Cheese Croissant,                 
##        Orange Juice}          0.038    38
## [64]  {Apricot Danish,                   
##        Cherry Tart,                      
##        Opera Cake}            0.038    38
## [65]  {Vanilla Eclair}        0.037    37
## [66]  {Casino Cake,                      
##        Chocolate Cake,                   
##        Chocolate Coffee}      0.037    37
## [67]  {Chocolate Eclair}      0.034    34
## [68]  {Berry Tart,                       
##        Bottled Water}         0.034    34
## [69]  {Apple Tart,                       
##        Cherry Soda}           0.034    34
## [70]  {Apple Pie,                        
##        Coffee Eclair}         0.033    33
## [71]  {Lemon Cookie,                     
##        Raspberry Cookie}      0.033    33
## [72]  {Blueberry Tart,                   
##        Hot Coffee}            0.033    33
## [73]  {Apricot Croissant,                
##        Hot Coffee}            0.032    32
## [74]  {Apricot Croissant,                
##        Blueberry Tart,                   
##        Hot Coffee}            0.032    32
## [75]  {Blackberry Tart,                  
##        Coffee Eclair}         0.031    31
## [76]  {Lemon Cookie,                     
##        Lemon Lemonade}        0.031    31
## [77]  {Lemon Lemonade,                   
##        Raspberry Cookie}      0.031    31
## [78]  {Apple Danish,                     
##        Cherry Soda}           0.031    31
## [79]  {Apple Croissant,                  
##        Cherry Soda}           0.031    31
## [80]  {Almond Twist,                     
##        Coffee Eclair}         0.030    30
## [81]  {Lemon Cookie,                     
##        Raspberry Lemonade}    0.030    30
## [82]  {Almond Twist,                     
##        Apple Pie}             0.029    29
## [83]  {Lemon Lemonade,                   
##        Raspberry Lemonade}    0.029    29
## [84]  {Apple Pie,                        
##        Hot Coffee}            0.029    29
## [85]  {Raspberry Cookie,                 
##        Raspberry Lemonade}    0.029    29
## [86]  {Lemon Cookie,                     
##        Raspberry Cookie,                 
##        Raspberry Lemonade}    0.029    29
## [87]  {Apple Danish,                     
##        Apple Tart,                       
##        Cherry Soda}           0.029    29
## [88]  {Apple Croissant,                  
##        Apple Tart,                       
##        Cherry Soda}           0.029    29
## [89]  {Apple Croissant,                  
##        Apple Danish,                     
##        Cherry Soda}           0.029    29
## [90]  {Apple Croissant,                  
##        Apple Danish,                     
##        Apple Tart,                       
##        Cherry Soda}           0.029    29
## [91]  {Lemon Cookie,                     
##        Lemon Lemonade,                   
##        Raspberry Lemonade}    0.028    28
## [92]  {Lemon Cookie,                     
##        Lemon Lemonade,                   
##        Raspberry Cookie}      0.028    28
## [93]  {Lemon Lemonade,                   
##        Raspberry Cookie,                 
##        Raspberry Lemonade}    0.028    28
## [94]  {Lemon Cookie,                     
##        Lemon Lemonade,                   
##        Raspberry Cookie,                 
##        Raspberry Lemonade}    0.028    28
## [95]  {Almond Twist,                     
##        Apple Pie,                        
##        Coffee Eclair}         0.027    27
## [96]  {Almond Bear Claw}      0.026    26
## [97]  {Chocolate Tart,                   
##        Vanilla Frappuccino}   0.026    26
## [98]  {Coffee Eclair,                    
##        Hot Coffee}            0.026    26
## [99]  {Almond Twist,                     
##        Hot Coffee}            0.025    25
## [100] {Blackberry Tart,                  
##        Single Espresso}       0.024    24
## [101] {Coffee Eclair,                    
##        Single Espresso}       0.024    24
## [102] {Almond Twist,                     
##        Apple Pie,                        
##        Hot Coffee}            0.024    24
## [103] {Almond Twist,                     
##        Coffee Eclair,                    
##        Hot Coffee}            0.024    24
## [104] {Apple Pie,                        
##        Coffee Eclair,                    
##        Hot Coffee}            0.024    24
## [105] {Almond Twist,                     
##        Apple Pie,                        
##        Coffee Eclair,                    
##        Hot Coffee}            0.024    24
## [106] {Green Tea,                        
##        Raspberry Lemonade}    0.023    23
## [107] {Blackberry Tart,                  
##        Coffee Eclair,                    
##        Single Espresso}       0.023    23
## [108] {Green Tea,                        
##        Lemon Lemonade}        0.021    21
## [109] {Green Tea,                        
##        Lemon Cookie}          0.020    20
## [110] {Green Tea,                        
##        Raspberry Cookie}      0.020    20
## [111] {Green Tea,                        
##        Lemon Cookie,                     
##        Lemon Lemonade}        0.019    19
## [112] {Green Tea,                        
##        Lemon Lemonade,                   
##        Raspberry Lemonade}    0.019    19
## [113] {Green Tea,                        
##        Lemon Lemonade,                   
##        Raspberry Cookie}      0.019    19
## [114] {Green Tea,                        
##        Lemon Cookie,                     
##        Raspberry Lemonade}    0.019    19
## [115] {Green Tea,                        
##        Lemon Cookie,                     
##        Raspberry Cookie}      0.019    19
## [116] {Green Tea,                        
##        Raspberry Cookie,                 
##        Raspberry Lemonade}    0.019    19
## [117] {Green Tea,                        
##        Lemon Cookie,                     
##        Lemon Lemonade,                   
##        Raspberry Lemonade}    0.019    19
## [118] {Green Tea,                        
##        Lemon Cookie,                     
##        Lemon Lemonade,                   
##        Raspberry Cookie}      0.019    19
## [119] {Green Tea,                        
##        Lemon Lemonade,                   
##        Raspberry Cookie,                 
##        Raspberry Lemonade}    0.019    19
## [120] {Green Tea,                        
##        Lemon Cookie,                     
##        Raspberry Cookie,                 
##        Raspberry Lemonade}    0.019    19
## [121] {Green Tea,                        
##        Lemon Cookie,                     
##        Lemon Lemonade,                   
##        Raspberry Cookie,                 
##        Raspberry Lemonade}    0.019    19
rules1 <- apriori(transact1, parameter=list(support = 0.019, confidence=0.94))# changed from confidence = 0.9
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##        0.94    0.1    1 none FALSE            TRUE       5   0.019      1
##  maxlen target  ext
##      10  rules TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 19 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[50 item(s), 1000 transaction(s)] done [0.00s].
## sorting and recoding items ... [50 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 4 5 done [0.00s].
## writing ... [47 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
summary(rules1)
## set of 47 rules
## 
## rule length distribution (lhs + rhs):sizes
##  3  4  5 
## 21 22  4 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   3.000   3.000   4.000   3.638   4.000   5.000 
## 
## summary of quality measures:
##     support          confidence        coverage            lift      
##  Min.   :0.01900   Min.   :0.9500   Min.   :0.01900   Min.   :10.30  
##  1st Qu.:0.01900   1st Qu.:0.9655   1st Qu.:0.01900   1st Qu.:12.13  
##  Median :0.02300   Median :1.0000   Median :0.02400   Median :13.89  
##  Mean   :0.02434   Mean   :0.9832   Mean   :0.02479   Mean   :13.33  
##  3rd Qu.:0.02800   3rd Qu.:1.0000   3rd Qu.:0.02900   3rd Qu.:14.67  
##  Max.   :0.04000   Max.   :1.0000   Max.   :0.04200   Max.   :15.62  
##      count      
##  Min.   :19.00  
##  1st Qu.:19.00  
##  Median :23.00  
##  Mean   :24.34  
##  3rd Qu.:28.00  
##  Max.   :40.00  
## 
## mining info:
##       data ntransactions support confidence
##  transact1          1000   0.019       0.94
##                                                                             call
##  apriori(data = transact1, parameter = list(support = 0.019, confidence = 0.94))
#inspect(rules1, by="confidence")
inspect(rules1, by="lift")
##      lhs                     rhs                  support confidence coverage     lift count
## [1]  {Blackberry Tart,                                                                      
##       Single Espresso}    => {Coffee Eclair}        0.023  0.9583333    0.024 10.30466    23
## [2]  {Coffee Eclair,                                                                        
##       Single Espresso}    => {Blackberry Tart}      0.023  0.9583333    0.024 13.12785    23
## [3]  {Almond Twist,                                                                         
##       Hot Coffee}         => {Apple Pie}            0.024  0.9600000    0.025 14.11765    24
## [4]  {Almond Twist,                                                                         
##       Hot Coffee}         => {Coffee Eclair}        0.024  0.9600000    0.025 10.32258    24
## [5]  {Green Tea,                                                                            
##       Lemon Cookie}       => {Lemon Lemonade}       0.019  0.9500000    0.020 14.39394    19
## [6]  {Green Tea,                                                                            
##       Raspberry Cookie}   => {Lemon Lemonade}       0.019  0.9500000    0.020 14.39394    19
## [7]  {Lemon Lemonade,                                                                       
##       Raspberry Lemonade} => {Lemon Cookie}         0.028  0.9655172    0.029 14.62905    28
## [8]  {Lemon Lemonade,                                                                       
##       Raspberry Lemonade} => {Raspberry Cookie}     0.028  0.9655172    0.029 11.77460    28
## [9]  {Raspberry Cookie,                                                                     
##       Raspberry Lemonade} => {Lemon Lemonade}       0.028  0.9655172    0.029 14.62905    28
## [10] {Green Tea,                                                                            
##       Lemon Cookie}       => {Raspberry Lemonade}   0.019  0.9500000    0.020 13.19444    19
## [11] {Green Tea,                                                                            
##       Lemon Cookie}       => {Raspberry Cookie}     0.019  0.9500000    0.020 11.58537    19
## [12] {Green Tea,                                                                            
##       Raspberry Cookie}   => {Lemon Cookie}         0.019  0.9500000    0.020 14.39394    19
## [13] {Green Tea,                                                                            
##       Raspberry Cookie}   => {Raspberry Lemonade}   0.019  0.9500000    0.020 13.19444    19
## [14] {Casino Cake,                                                                          
##       Chocolate Coffee}   => {Chocolate Cake}       0.037  0.9736842    0.038 11.59148    37
## [15] {Apricot Croissant,                                                                    
##       Hot Coffee}         => {Blueberry Tart}       0.032  1.0000000    0.032 12.34568    32
## [16] {Blueberry Tart,                                                                       
##       Hot Coffee}         => {Apricot Croissant}    0.032  0.9696970    0.033 12.75917    32
## [17] {Lemon Cookie,                                                                         
##       Raspberry Lemonade} => {Raspberry Cookie}     0.029  0.9666667    0.030 11.78862    29
## [18] {Raspberry Cookie,                                                                     
##       Raspberry Lemonade} => {Lemon Cookie}         0.029  1.0000000    0.029 15.15152    29
## [19] {Apricot Danish,                                                                       
##       Opera Cake}         => {Cherry Tart}          0.038  0.9743590    0.039 11.59951    38
## [20] {Apple Danish,                                                                         
##       Apple Tart}         => {Apple Croissant}      0.040  0.9756098    0.041 10.84011    40
## [21] {Apple Croissant,                                                                      
##       Apple Danish}       => {Apple Tart}           0.040  0.9523810    0.042 12.05546    40
## [22] {Almond Twist,                                                                         
##       Apple Pie,                                                                            
##       Hot Coffee}         => {Coffee Eclair}        0.024  1.0000000    0.024 10.75269    24
## [23] {Almond Twist,                                                                         
##       Coffee Eclair,                                                                        
##       Hot Coffee}         => {Apple Pie}            0.024  1.0000000    0.024 14.70588    24
## [24] {Apple Pie,                                                                            
##       Coffee Eclair,                                                                        
##       Hot Coffee}         => {Almond Twist}         0.024  1.0000000    0.024 15.62500    24
## [25] {Green Tea,                                                                            
##       Lemon Cookie,                                                                         
##       Lemon Lemonade}     => {Raspberry Lemonade}   0.019  1.0000000    0.019 13.88889    19
## [26] {Green Tea,                                                                            
##       Lemon Lemonade,                                                                       
##       Raspberry Lemonade} => {Lemon Cookie}         0.019  1.0000000    0.019 15.15152    19
## [27] {Green Tea,                                                                            
##       Lemon Cookie,                                                                         
##       Raspberry Lemonade} => {Lemon Lemonade}       0.019  1.0000000    0.019 15.15152    19
## [28] {Green Tea,                                                                            
##       Lemon Cookie,                                                                         
##       Lemon Lemonade}     => {Raspberry Cookie}     0.019  1.0000000    0.019 12.19512    19
## [29] {Green Tea,                                                                            
##       Lemon Lemonade,                                                                       
##       Raspberry Cookie}   => {Lemon Cookie}         0.019  1.0000000    0.019 15.15152    19
## [30] {Green Tea,                                                                            
##       Lemon Cookie,                                                                         
##       Raspberry Cookie}   => {Lemon Lemonade}       0.019  1.0000000    0.019 15.15152    19
## [31] {Green Tea,                                                                            
##       Lemon Lemonade,                                                                       
##       Raspberry Lemonade} => {Raspberry Cookie}     0.019  1.0000000    0.019 12.19512    19
## [32] {Green Tea,                                                                            
##       Lemon Lemonade,                                                                       
##       Raspberry Cookie}   => {Raspberry Lemonade}   0.019  1.0000000    0.019 13.88889    19
## [33] {Green Tea,                                                                            
##       Raspberry Cookie,                                                                     
##       Raspberry Lemonade} => {Lemon Lemonade}       0.019  1.0000000    0.019 15.15152    19
## [34] {Lemon Cookie,                                                                         
##       Lemon Lemonade,                                                                       
##       Raspberry Lemonade} => {Raspberry Cookie}     0.028  1.0000000    0.028 12.19512    28
## [35] {Lemon Cookie,                                                                         
##       Lemon Lemonade,                                                                       
##       Raspberry Cookie}   => {Raspberry Lemonade}   0.028  1.0000000    0.028 13.88889    28
## [36] {Lemon Lemonade,                                                                       
##       Raspberry Cookie,                                                                     
##       Raspberry Lemonade} => {Lemon Cookie}         0.028  1.0000000    0.028 15.15152    28
## [37] {Lemon Cookie,                                                                         
##       Raspberry Cookie,                                                                     
##       Raspberry Lemonade} => {Lemon Lemonade}       0.028  0.9655172    0.029 14.62905    28
## [38] {Green Tea,                                                                            
##       Lemon Cookie,                                                                         
##       Raspberry Lemonade} => {Raspberry Cookie}     0.019  1.0000000    0.019 12.19512    19
## [39] {Green Tea,                                                                            
##       Lemon Cookie,                                                                         
##       Raspberry Cookie}   => {Raspberry Lemonade}   0.019  1.0000000    0.019 13.88889    19
## [40] {Green Tea,                                                                            
##       Raspberry Cookie,                                                                     
##       Raspberry Lemonade} => {Lemon Cookie}         0.019  1.0000000    0.019 15.15152    19
## [41] {Apple Danish,                                                                         
##       Apple Tart,                                                                           
##       Cherry Soda}        => {Apple Croissant}      0.029  1.0000000    0.029 11.11111    29
## [42] {Apple Croissant,                                                                      
##       Apple Tart,                                                                           
##       Cherry Soda}        => {Apple Danish}         0.029  1.0000000    0.029 11.90476    29
## [43] {Apple Croissant,                                                                      
##       Apple Danish,                                                                         
##       Cherry Soda}        => {Apple Tart}           0.029  1.0000000    0.029 12.65823    29
## [44] {Green Tea,                                                                            
##       Lemon Cookie,                                                                         
##       Lemon Lemonade,                                                                       
##       Raspberry Lemonade} => {Raspberry Cookie}     0.019  1.0000000    0.019 12.19512    19
## [45] {Green Tea,                                                                            
##       Lemon Cookie,                                                                         
##       Lemon Lemonade,                                                                       
##       Raspberry Cookie}   => {Raspberry Lemonade}   0.019  1.0000000    0.019 13.88889    19
## [46] {Green Tea,                                                                            
##       Lemon Lemonade,                                                                       
##       Raspberry Cookie,                                                                     
##       Raspberry Lemonade} => {Lemon Cookie}         0.019  1.0000000    0.019 15.15152    19
## [47] {Green Tea,                                                                            
##       Lemon Cookie,                                                                         
##       Raspberry Cookie,                                                                     
##       Raspberry Lemonade} => {Lemon Lemonade}       0.019  1.0000000    0.019 15.15152    19
plot(rules1, engine="htmlwidget", main="1K data Lift on Confidence vs Support")
## To reduce overplotting, jitter is added! Use jitter = 0 to prevent jitter.

ii - Applying Apriori - 5K

#minSup, minConf
frequent_list2 <- apriori(transact2, parameter=list(support = 0.019, target="frequent itemsets"))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##          NA    0.1    1 none FALSE            TRUE       5   0.019      1
##  maxlen            target  ext
##      10 frequent itemsets TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 95 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[50 item(s), 5000 transaction(s)] done [0.00s].
## sorting and recoding items ... [50 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 4 5 done [0.00s].
## sorting transactions ... done [0.00s].
## writing ... [124 set(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
inspect(sort(frequent_list2, decreasing = T, by="support"))
##       items                  support count
## [1]   {Coffee Eclair}         0.1108   554
## [2]   {Hot Coffee}            0.0998   499
## [3]   {Tuile Cookie}          0.0996   498
## [4]   {Strawberry Cake}       0.0960   480
## [5]   {Gongolais Cookie}      0.0954   477
## [6]   {Cherry Tart}           0.0920   460
## [7]   {Orange Juice}          0.0912   456
## [8]   {Apricot Danish}        0.0890   445
## [9]   {Truffle Cake}          0.0876   438
## [10]  {Blueberry Tart}        0.0852   426
## [11]  {Lemon Cake}            0.0850   425
## [12]  {Marzipan Cookie}       0.0836   418
## [13]  {Opera Cake}            0.0836   418
## [14]  {Apricot Croissant}     0.0822   411
## [15]  {Napoleon Cake}         0.0818   409
## [16]  {Almond Twist}          0.0810   405
## [17]  {Chocolate Cake}        0.0798   399
## [18]  {Chocolate Coffee}      0.0788   394
## [19]  {Berry Tart}            0.0782   391
## [20]  {Apple Danish}          0.0782   391
## [21]  {Apple Pie}             0.0782   391
## [22]  {Cheese Croissant}      0.0770   385
## [23]  {Bottled Water}         0.0764   382
## [24]  {Chocolate Tart}        0.0762   381
## [25]  {Blackberry Tart}       0.0760   380
## [26]  {Casino Cake}           0.0746   373
## [27]  {Apple Croissant}       0.0742   371
## [28]  {Apple Tart}            0.0734   367
## [29]  {Lemon Tart}            0.0708   354
## [30]  {Vanilla Frappuccino}   0.0706   353
## [31]  {Walnut Cookie}         0.0706   353
## [32]  {Raspberry Lemonade}    0.0666   333
## [33]  {Lemon Lemonade}        0.0648   324
## [34]  {Cherry Soda}           0.0646   323
## [35]  {Lemon Cookie}          0.0642   321
## [36]  {Raspberry Cookie}      0.0640   320
## [37]  {Single Espresso}       0.0618   309
## [38]  {Green Tea}             0.0606   303
## [39]  {Apricot Danish,                    
##        Cherry Tart}           0.0512   256
## [40]  {Marzipan Cookie,                   
##        Tuile Cookie}          0.0494   247
## [41]  {Gongolais Cookie,                  
##        Truffle Cake}          0.0472   236
## [42]  {Vanilla Eclair}        0.0460   230
## [43]  {Almond Croissant}      0.0456   228
## [44]  {Chocolate Meringue}    0.0452   226
## [45]  {Pecan Tart}            0.0444   222
## [46]  {Apricot Croissant,                 
##        Blueberry Tart}        0.0440   220
## [47]  {Cherry Tart,                       
##        Opera Cake}            0.0436   218
## [48]  {Chocolate Croissant}   0.0432   216
## [49]  {Apricot Danish,                    
##        Opera Cake}            0.0432   216
## [50]  {Apricot Tart}          0.0422   211
## [51]  {Almond Bear Claw}      0.0422   211
## [52]  {Cheese Croissant,                  
##        Orange Juice}          0.0422   211
## [53]  {Napoleon Cake,                     
##        Strawberry Cake}       0.0422   211
## [54]  {Almond Twist,                      
##        Coffee Eclair}         0.0410   205
## [55]  {Apricot Danish,                    
##        Cherry Tart,                       
##        Opera Cake}            0.0408   204
## [56]  {Apple Pie,                         
##        Coffee Eclair}         0.0406   203
## [57]  {Vanilla Meringue}      0.0398   199
## [58]  {Almond Twist,                      
##        Apple Pie}             0.0392   196
## [59]  {Chocolate Cake,                    
##        Chocolate Coffee}      0.0390   195
## [60]  {Ganache Cookie}        0.0388   194
## [61]  {Blueberry Danish}      0.0388   194
## [62]  {Almond Tart}           0.0386   193
## [63]  {Chocolate Eclair}      0.0382   191
## [64]  {Almond Twist,                      
##        Apple Pie,                         
##        Coffee Eclair}         0.0380   190
## [65]  {Berry Tart,                        
##        Bottled Water}         0.0366   183
## [66]  {Blackberry Tart,                   
##        Coffee Eclair}         0.0356   178
## [67]  {Casino Cake,                       
##        Chocolate Cake}        0.0342   171
## [68]  {Apricot Croissant,                 
##        Hot Coffee}            0.0340   170
## [69]  {Chocolate Tart,                    
##        Vanilla Frappuccino}   0.0338   169
## [70]  {Casino Cake,                       
##        Chocolate Coffee}      0.0338   169
## [71]  {Blueberry Tart,                    
##        Hot Coffee}            0.0338   169
## [72]  {Lemon Cake,                        
##        Lemon Tart}            0.0336   168
## [73]  {Apple Croissant,                   
##        Apple Danish}          0.0330   165
## [74]  {Almond Twist,                      
##        Hot Coffee}            0.0326   163
## [75]  {Apple Danish,                      
##        Apple Tart}            0.0324   162
## [76]  {Apple Pie,                         
##        Hot Coffee}            0.0324   162
## [77]  {Coffee Eclair,                     
##        Hot Coffee}            0.0322   161
## [78]  {Apricot Croissant,                 
##        Blueberry Tart,                    
##        Hot Coffee}            0.0320   160
## [79]  {Apple Croissant,                   
##        Apple Tart}            0.0316   158
## [80]  {Casino Cake,                       
##        Chocolate Cake,                    
##        Chocolate Coffee}      0.0308   154
## [81]  {Blackberry Tart,                   
##        Single Espresso}       0.0300   150
## [82]  {Apple Croissant,                   
##        Apple Danish,                      
##        Apple Tart}            0.0298   149
## [83]  {Almond Twist,                      
##        Apple Pie,                         
##        Hot Coffee}            0.0298   149
## [84]  {Apple Pie,                         
##        Coffee Eclair,                     
##        Hot Coffee}            0.0298   149
## [85]  {Almond Twist,                      
##        Coffee Eclair,                     
##        Hot Coffee}            0.0298   149
## [86]  {Almond Twist,                      
##        Apple Pie,                         
##        Coffee Eclair,                     
##        Hot Coffee}            0.0298   149
## [87]  {Vanilla Frappuccino,               
##        Walnut Cookie}         0.0288   144
## [88]  {Chocolate Tart,                    
##        Walnut Cookie}         0.0286   143
## [89]  {Coffee Eclair,                     
##        Single Espresso}       0.0284   142
## [90]  {Raspberry Cookie,                  
##        Raspberry Lemonade}    0.0284   142
## [91]  {Lemon Cookie,                      
##        Raspberry Cookie}      0.0284   142
## [92]  {Lemon Cookie,                      
##        Raspberry Lemonade}    0.0282   141
## [93]  {Lemon Cookie,                      
##        Lemon Lemonade}        0.0280   140
## [94]  {Lemon Lemonade,                    
##        Raspberry Cookie}      0.0278   139
## [95]  {Lemon Lemonade,                    
##        Raspberry Lemonade}    0.0278   139
## [96]  {Blackberry Tart,                   
##        Coffee Eclair,                     
##        Single Espresso}       0.0274   137
## [97]  {Lemon Cookie,                      
##        Lemon Lemonade,                    
##        Raspberry Cookie}      0.0264   132
## [98]  {Lemon Cookie,                      
##        Lemon Lemonade,                    
##        Raspberry Lemonade}    0.0264   132
## [99]  {Lemon Lemonade,                    
##        Raspberry Cookie,                  
##        Raspberry Lemonade}    0.0262   131
## [100] {Lemon Cookie,                      
##        Raspberry Cookie,                  
##        Raspberry Lemonade}    0.0262   131
## [101] {Lemon Cookie,                      
##        Lemon Lemonade,                    
##        Raspberry Cookie,                  
##        Raspberry Lemonade}    0.0262   131
## [102] {Chocolate Tart,                    
##        Vanilla Frappuccino,               
##        Walnut Cookie}         0.0260   130
## [103] {Apple Tart,                        
##        Cherry Soda}           0.0246   123
## [104] {Apple Croissant,                   
##        Cherry Soda}           0.0246   123
## [105] {Apple Danish,                      
##        Cherry Soda}           0.0242   121
## [106] {Green Tea,                         
##        Raspberry Lemonade}    0.0238   119
## [107] {Green Tea,                         
##        Lemon Cookie}          0.0228   114
## [108] {Green Tea,                         
##        Raspberry Cookie}      0.0226   113
## [109] {Apple Croissant,                   
##        Apple Tart,                        
##        Cherry Soda}           0.0226   113
## [110] {Apple Croissant,                   
##        Apple Danish,                      
##        Cherry Soda}           0.0226   113
## [111] {Apple Danish,                      
##        Apple Tart,                        
##        Cherry Soda}           0.0224   112
## [112] {Apple Croissant,                   
##        Apple Danish,                      
##        Apple Tart,                        
##        Cherry Soda}           0.0224   112
## [113] {Green Tea,                         
##        Lemon Lemonade}        0.0218   109
## [114] {Green Tea,                         
##        Lemon Cookie,                      
##        Raspberry Cookie}      0.0208   104
## [115] {Green Tea,                         
##        Lemon Lemonade,                    
##        Raspberry Cookie}      0.0206   103
## [116] {Green Tea,                         
##        Lemon Lemonade,                    
##        Raspberry Lemonade}    0.0206   103
## [117] {Green Tea,                         
##        Lemon Cookie,                      
##        Lemon Lemonade}        0.0206   103
## [118] {Green Tea,                         
##        Raspberry Cookie,                  
##        Raspberry Lemonade}    0.0206   103
## [119] {Green Tea,                         
##        Lemon Cookie,                      
##        Raspberry Lemonade}    0.0206   103
## [120] {Green Tea,                         
##        Lemon Lemonade,                    
##        Raspberry Cookie,                  
##        Raspberry Lemonade}    0.0206   103
## [121] {Green Tea,                         
##        Lemon Cookie,                      
##        Lemon Lemonade,                    
##        Raspberry Cookie}      0.0206   103
## [122] {Green Tea,                         
##        Lemon Cookie,                      
##        Lemon Lemonade,                    
##        Raspberry Lemonade}    0.0206   103
## [123] {Green Tea,                         
##        Lemon Cookie,                      
##        Raspberry Cookie,                  
##        Raspberry Lemonade}    0.0206   103
## [124] {Green Tea,                         
##        Lemon Cookie,                      
##        Lemon Lemonade,                    
##        Raspberry Cookie,                  
##        Raspberry Lemonade}    0.0206   103
rules2 <- apriori(transact2, parameter=list(support = 0.019, confidence=0.94))#, confidence = 0.6
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##        0.94    0.1    1 none FALSE            TRUE       5   0.019      1
##  maxlen target  ext
##      10  rules TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 95 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[50 item(s), 5000 transaction(s)] done [0.00s].
## sorting and recoding items ... [50 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 4 5 done [0.00s].
## writing ... [41 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
summary(rules2)
## set of 41 rules
## 
## rule length distribution (lhs + rhs):sizes
##  3  4  5 
## 15 22  4 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   3.000   3.000   4.000   3.732   4.000   5.000 
## 
## summary of quality measures:
##     support          confidence        coverage            lift       
##  Min.   :0.02060   Min.   :0.9412   Min.   :0.02060   Min.   : 8.749  
##  1st Qu.:0.02060   1st Qu.:0.9467   1st Qu.:0.02060   1st Qu.:13.477  
##  Median :0.02240   Median :0.9924   Median :0.02260   Median :14.792  
##  Mean   :0.02465   Mean   :0.9796   Mean   :0.02524   Mean   :14.119  
##  3rd Qu.:0.02640   3rd Qu.:1.0000   3rd Qu.:0.02800   3rd Qu.:15.432  
##  Max.   :0.04080   Max.   :1.0000   Max.   :0.04320   Max.   :15.625  
##      count      
##  Min.   :103.0  
##  1st Qu.:103.0  
##  Median :112.0  
##  Mean   :123.3  
##  3rd Qu.:132.0  
##  Max.   :204.0  
## 
## mining info:
##       data ntransactions support confidence
##  transact2          5000   0.019       0.94
##                                                                             call
##  apriori(data = transact2, parameter = list(support = 0.019, confidence = 0.94))
#inspect(rules2, by="confidence")
inspect(rules2, by="lift")
##      lhs                     rhs                  support confidence coverage      lift count
## [1]  {Coffee Eclair,                                                                         
##       Single Espresso}    => {Blackberry Tart}     0.0274  0.9647887   0.0284 12.694589   137
## [2]  {Green Tea,                                                                             
##       Lemon Lemonade}     => {Raspberry Cookie}    0.0206  0.9449541   0.0218 14.764908   103
## [3]  {Green Tea,                                                                             
##       Lemon Lemonade}     => {Raspberry Lemonade}  0.0206  0.9449541   0.0218 14.188500   103
## [4]  {Green Tea,                                                                             
##       Lemon Lemonade}     => {Lemon Cookie}        0.0206  0.9449541   0.0218 14.718912   103
## [5]  {Lemon Lemonade,                                                                        
##       Raspberry Cookie}   => {Raspberry Lemonade}  0.0262  0.9424460   0.0278 14.150841   131
## [6]  {Lemon Lemonade,                                                                        
##       Raspberry Lemonade} => {Raspberry Cookie}    0.0262  0.9424460   0.0278 14.725719   131
## [7]  {Lemon Lemonade,                                                                        
##       Raspberry Cookie}   => {Lemon Cookie}        0.0264  0.9496403   0.0278 14.791905   132
## [8]  {Lemon Cookie,                                                                          
##       Lemon Lemonade}     => {Raspberry Cookie}    0.0264  0.9428571   0.0280 14.732143   132
## [9]  {Lemon Lemonade,                                                                        
##       Raspberry Lemonade} => {Lemon Cookie}        0.0264  0.9496403   0.0278 14.791905   132
## [10] {Lemon Cookie,                                                                          
##       Lemon Lemonade}     => {Raspberry Lemonade}  0.0264  0.9428571   0.0280 14.157014   132
## [11] {Apple Croissant,                                                                       
##       Apple Tart}         => {Apple Danish}        0.0298  0.9430380   0.0316 12.059309   149
## [12] {Apricot Croissant,                                                                     
##       Hot Coffee}         => {Blueberry Tart}      0.0320  0.9411765   0.0340 11.046672   160
## [13] {Blueberry Tart,                                                                        
##       Hot Coffee}         => {Apricot Croissant}   0.0320  0.9467456   0.0338 11.517586   160
## [14] {Apricot Danish,                                                                        
##       Opera Cake}         => {Cherry Tart}         0.0408  0.9444444   0.0432 10.265700   204
## [15] {Almond Twist,                                                                          
##       Apple Pie}          => {Coffee Eclair}       0.0380  0.9693878   0.0392  8.748987   190
## [16] {Apple Croissant,                                                                       
##       Apple Tart,                                                                            
##       Cherry Soda}        => {Apple Danish}        0.0224  0.9911504   0.0226 12.674558   112
## [17] {Apple Danish,                                                                          
##       Apple Tart,                                                                            
##       Cherry Soda}        => {Apple Croissant}     0.0224  1.0000000   0.0224 13.477089   112
## [18] {Apple Croissant,                                                                       
##       Apple Danish,                                                                          
##       Cherry Soda}        => {Apple Tart}          0.0224  0.9911504   0.0226 13.503412   112
## [19] {Green Tea,                                                                             
##       Lemon Lemonade,                                                                        
##       Raspberry Cookie}   => {Raspberry Lemonade}  0.0206  1.0000000   0.0206 15.015015   103
## [20] {Green Tea,                                                                             
##       Lemon Lemonade,                                                                        
##       Raspberry Lemonade} => {Raspberry Cookie}    0.0206  1.0000000   0.0206 15.625000   103
## [21] {Green Tea,                                                                             
##       Raspberry Cookie,                                                                      
##       Raspberry Lemonade} => {Lemon Lemonade}      0.0206  1.0000000   0.0206 15.432099   103
## [22] {Green Tea,                                                                             
##       Lemon Lemonade,                                                                        
##       Raspberry Cookie}   => {Lemon Cookie}        0.0206  1.0000000   0.0206 15.576324   103
## [23] {Green Tea,                                                                             
##       Lemon Cookie,                                                                          
##       Lemon Lemonade}     => {Raspberry Cookie}    0.0206  1.0000000   0.0206 15.625000   103
## [24] {Green Tea,                                                                             
##       Lemon Cookie,                                                                          
##       Raspberry Cookie}   => {Lemon Lemonade}      0.0206  0.9903846   0.0208 15.283713   103
## [25] {Green Tea,                                                                             
##       Lemon Lemonade,                                                                        
##       Raspberry Lemonade} => {Lemon Cookie}        0.0206  1.0000000   0.0206 15.576324   103
## [26] {Green Tea,                                                                             
##       Lemon Cookie,                                                                          
##       Lemon Lemonade}     => {Raspberry Lemonade}  0.0206  1.0000000   0.0206 15.015015   103
## [27] {Green Tea,                                                                             
##       Lemon Cookie,                                                                          
##       Raspberry Lemonade} => {Lemon Lemonade}      0.0206  1.0000000   0.0206 15.432099   103
## [28] {Green Tea,                                                                             
##       Raspberry Cookie,                                                                      
##       Raspberry Lemonade} => {Lemon Cookie}        0.0206  1.0000000   0.0206 15.576324   103
## [29] {Green Tea,                                                                             
##       Lemon Cookie,                                                                          
##       Raspberry Cookie}   => {Raspberry Lemonade}  0.0206  0.9903846   0.0208 14.870640   103
## [30] {Green Tea,                                                                             
##       Lemon Cookie,                                                                          
##       Raspberry Lemonade} => {Raspberry Cookie}    0.0206  1.0000000   0.0206 15.625000   103
## [31] {Lemon Lemonade,                                                                        
##       Raspberry Cookie,                                                                      
##       Raspberry Lemonade} => {Lemon Cookie}        0.0262  1.0000000   0.0262 15.576324   131
## [32] {Lemon Cookie,                                                                          
##       Lemon Lemonade,                                                                        
##       Raspberry Cookie}   => {Raspberry Lemonade}  0.0262  0.9924242   0.0264 14.901265   131
## [33] {Lemon Cookie,                                                                          
##       Lemon Lemonade,                                                                        
##       Raspberry Lemonade} => {Raspberry Cookie}    0.0262  0.9924242   0.0264 15.506629   131
## [34] {Lemon Cookie,                                                                          
##       Raspberry Cookie,                                                                      
##       Raspberry Lemonade} => {Lemon Lemonade}      0.0262  1.0000000   0.0262 15.432099   131
## [35] {Almond Twist,                                                                          
##       Apple Pie,                                                                             
##       Hot Coffee}         => {Coffee Eclair}       0.0298  1.0000000   0.0298  9.025271   149
## [36] {Apple Pie,                                                                             
##       Coffee Eclair,                                                                         
##       Hot Coffee}         => {Almond Twist}        0.0298  1.0000000   0.0298 12.345679   149
## [37] {Almond Twist,                                                                          
##       Coffee Eclair,                                                                         
##       Hot Coffee}         => {Apple Pie}           0.0298  1.0000000   0.0298 12.787724   149
## [38] {Green Tea,                                                                             
##       Lemon Lemonade,                                                                        
##       Raspberry Cookie,                                                                      
##       Raspberry Lemonade} => {Lemon Cookie}        0.0206  1.0000000   0.0206 15.576324   103
## [39] {Green Tea,                                                                             
##       Lemon Cookie,                                                                          
##       Lemon Lemonade,                                                                        
##       Raspberry Cookie}   => {Raspberry Lemonade}  0.0206  1.0000000   0.0206 15.015015   103
## [40] {Green Tea,                                                                             
##       Lemon Cookie,                                                                          
##       Lemon Lemonade,                                                                        
##       Raspberry Lemonade} => {Raspberry Cookie}    0.0206  1.0000000   0.0206 15.625000   103
## [41] {Green Tea,                                                                             
##       Lemon Cookie,                                                                          
##       Raspberry Cookie,                                                                      
##       Raspberry Lemonade} => {Lemon Lemonade}      0.0206  1.0000000   0.0206 15.432099   103
plot(rules2, engine="htmlwidget", main="5K data Lift on Confidence vs Support")
## To reduce overplotting, jitter is added! Use jitter = 0 to prevent jitter.

iii- Applying Apriori - 20K

#minSup, minConf

frequent_list3 <- apriori(transact3, parameter=list(support = 0.019, target="frequent itemsets"))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##          NA    0.1    1 none FALSE            TRUE       5   0.019      1
##  maxlen            target  ext
##      10 frequent itemsets TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 380 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[50 item(s), 20000 transaction(s)] done [0.01s].
## sorting and recoding items ... [50 item(s)] done [0.00s].
## creating transaction tree ... done [0.01s].
## checking subsets of size 1 2 3 4 5 done [0.00s].
## sorting transactions ... done [0.01s].
## writing ... [124 set(s)] done [0.00s].
## creating S4 object  ... done [0.01s].
inspect(sort(frequent_list3, decreasing = T, by="support"))
##       items                  support count
## [1]   {Coffee Eclair}        0.10985  2197
## [2]   {Hot Coffee}           0.10125  2025
## [3]   {Tuile Cookie}         0.09860  1972
## [4]   {Apricot Danish}       0.09220  1844
## [5]   {Strawberry Cake}      0.09200  1840
## [6]   {Gongolais Cookie}     0.09185  1837
## [7]   {Orange Juice}         0.09160  1832
## [8]   {Cherry Tart}          0.09125  1825
## [9]   {Marzipan Cookie}      0.08640  1728
## [10]  {Lemon Cake}           0.08600  1720
## [11]  {Truffle Cake}         0.08465  1693
## [12]  {Napoleon Cake}        0.08450  1690
## [13]  {Berry Tart}           0.08430  1686
## [14]  {Blueberry Tart}       0.08390  1678
## [15]  {Chocolate Cake}       0.08365  1673
## [16]  {Opera Cake}           0.08365  1673
## [17]  {Apricot Croissant}    0.08165  1633
## [18]  {Cheese Croissant}     0.08160  1632
## [19]  {Chocolate Coffee}     0.07950  1590
## [20]  {Blackberry Tart}      0.07670  1534
## [21]  {Chocolate Tart}       0.07635  1527
## [22]  {Lemon Tart}           0.07595  1519
## [23]  {Casino Cake}          0.07530  1506
## [24]  {Vanilla Frappuccino}  0.07425  1485
## [25]  {Apple Pie}            0.07415  1483
## [26]  {Almond Twist}         0.07275  1455
## [27]  {Bottled Water}        0.07125  1425
## [28]  {Apple Croissant}      0.07085  1417
## [29]  {Walnut Cookie}        0.06950  1390
## [30]  {Raspberry Cookie}     0.06945  1389
## [31]  {Apple Tart}           0.06925  1385
## [32]  {Single Espresso}      0.06850  1370
## [33]  {Lemon Cookie}         0.06820  1364
## [34]  {Raspberry Lemonade}   0.06770  1354
## [35]  {Apple Danish}         0.06750  1350
## [36]  {Lemon Lemonade}       0.06605  1321
## [37]  {Cherry Soda}          0.06230  1246
## [38]  {Green Tea}            0.06100  1220
## [39]  {Apricot Danish,                    
##        Cherry Tart}          0.05235  1047
## [40]  {Marzipan Cookie,                   
##        Tuile Cookie}         0.04850   970
## [41]  {Napoleon Cake,                     
##        Strawberry Cake}      0.04455   891
## [42]  {Chocolate Meringue}   0.04445   889
## [43]  {Chocolate Croissant}  0.04445   889
## [44]  {Almond Bear Claw}     0.04400   880
## [45]  {Cheese Croissant,                  
##        Orange Juice}         0.04370   874
## [46]  {Cherry Tart,                       
##        Opera Cake}           0.04365   873
## [47]  {Gongolais Cookie,                  
##        Truffle Cake}         0.04335   867
## [48]  {Ganache Cookie}       0.04330   866
## [49]  {Apricot Danish,                    
##        Opera Cake}           0.04320   864
## [50]  {Chocolate Cake,                    
##        Chocolate Coffee}     0.04305   861
## [51]  {Apricot Tart}         0.04275   855
## [52]  {Vanilla Eclair}       0.04270   854
## [53]  {Chocolate Eclair}     0.04260   852
## [54]  {Vanilla Meringue}     0.04240   848
## [55]  {Almond Croissant}     0.04205   841
## [56]  {Apricot Croissant,                 
##        Blueberry Tart}       0.04185   837
## [57]  {Pecan Tart}           0.04155   831
## [58]  {Apricot Danish,                    
##        Cherry Tart,                       
##        Opera Cake}           0.04090   818
## [59]  {Blueberry Danish}     0.04065   813
## [60]  {Almond Tart}          0.04055   811
## [61]  {Apple Pie,                         
##        Coffee Eclair}        0.03725   745
## [62]  {Lemon Cake,                        
##        Lemon Tart}           0.03700   740
## [63]  {Blackberry Tart,                   
##        Coffee Eclair}        0.03675   735
## [64]  {Almond Twist,                      
##        Coffee Eclair}        0.03615   723
## [65]  {Casino Cake,                       
##        Chocolate Cake}       0.03585   717
## [66]  {Almond Twist,                      
##        Apple Pie}            0.03585   717
## [67]  {Chocolate Tart,                    
##        Vanilla Frappuccino}  0.03580   716
## [68]  {Berry Tart,                        
##        Bottled Water}        0.03535   707
## [69]  {Casino Cake,                       
##        Chocolate Coffee}     0.03505   701
## [70]  {Blueberry Tart,                    
##        Hot Coffee}           0.03475   695
## [71]  {Apricot Croissant,                 
##        Hot Coffee}           0.03425   685
## [72]  {Almond Twist,                      
##        Apple Pie,                         
##        Coffee Eclair}        0.03410   682
## [73]  {Casino Cake,                       
##        Chocolate Cake,                    
##        Chocolate Coffee}     0.03345   669
## [74]  {Apricot Croissant,                 
##        Blueberry Tart,                    
##        Hot Coffee}           0.03190   638
## [75]  {Coffee Eclair,                     
##        Hot Coffee}           0.03115   623
## [76]  {Chocolate Tart,                    
##        Walnut Cookie}        0.03055   611
## [77]  {Vanilla Frappuccino,               
##        Walnut Cookie}        0.03030   606
## [78]  {Almond Twist,                      
##        Hot Coffee}           0.03020   604
## [79]  {Apple Pie,                         
##        Hot Coffee}           0.03010   602
## [80]  {Blackberry Tart,                   
##        Single Espresso}      0.02935   587
## [81]  {Apple Croissant,                   
##        Apple Tart}           0.02865   573
## [82]  {Apple Croissant,                   
##        Apple Danish}         0.02860   572
## [83]  {Coffee Eclair,                     
##        Single Espresso}      0.02850   570
## [84]  {Lemon Cookie,                      
##        Raspberry Cookie}     0.02845   569
## [85]  {Lemon Cookie,                      
##        Raspberry Lemonade}   0.02815   563
## [86]  {Apple Danish,                      
##        Apple Tart}           0.02810   562
## [87]  {Almond Twist,                      
##        Apple Pie,                         
##        Hot Coffee}           0.02795   559
## [88]  {Lemon Lemonade,                    
##        Raspberry Cookie}     0.02790   558
## [89]  {Almond Twist,                      
##        Coffee Eclair,                     
##        Hot Coffee}           0.02785   557
## [90]  {Apple Pie,                         
##        Coffee Eclair,                     
##        Hot Coffee}           0.02785   557
## [91]  {Almond Twist,                      
##        Apple Pie,                         
##        Coffee Eclair,                     
##        Hot Coffee}           0.02785   557
## [92]  {Lemon Cookie,                      
##        Lemon Lemonade}       0.02775   555
## [93]  {Chocolate Tart,                    
##        Vanilla Frappuccino,               
##        Walnut Cookie}        0.02775   555
## [94]  {Raspberry Cookie,                  
##        Raspberry Lemonade}   0.02760   552
## [95]  {Lemon Lemonade,                    
##        Raspberry Lemonade}   0.02660   532
## [96]  {Blackberry Tart,                   
##        Coffee Eclair,                     
##        Single Espresso}      0.02640   528
## [97]  {Apple Croissant,                   
##        Apple Danish,                      
##        Apple Tart}           0.02600   520
## [98]  {Lemon Lemonade,                    
##        Raspberry Cookie,                  
##        Raspberry Lemonade}   0.02555   511
## [99]  {Lemon Cookie,                      
##        Lemon Lemonade,                    
##        Raspberry Cookie}     0.02555   511
## [100] {Lemon Cookie,                      
##        Raspberry Cookie,                  
##        Raspberry Lemonade}   0.02550   510
## [101] {Lemon Cookie,                      
##        Lemon Lemonade,                    
##        Raspberry Lemonade}   0.02545   509
## [102] {Lemon Cookie,                      
##        Lemon Lemonade,                    
##        Raspberry Cookie,                  
##        Raspberry Lemonade}   0.02535   507
## [103] {Apple Croissant,                   
##        Cherry Soda}          0.02320   464
## [104] {Apple Danish,                      
##        Cherry Soda}          0.02265   453
## [105] {Apple Tart,                        
##        Cherry Soda}          0.02235   447
## [106] {Green Tea,                         
##        Raspberry Cookie}     0.02235   447
## [107] {Green Tea,                         
##        Lemon Lemonade}       0.02210   442
## [108] {Green Tea,                         
##        Raspberry Lemonade}   0.02205   441
## [109] {Green Tea,                         
##        Lemon Cookie}         0.02200   440
## [110] {Apple Croissant,                   
##        Apple Danish,                      
##        Cherry Soda}          0.02075   415
## [111] {Apple Croissant,                   
##        Apple Tart,                        
##        Cherry Soda}          0.02070   414
## [112] {Apple Danish,                      
##        Apple Tart,                        
##        Cherry Soda}          0.02065   413
## [113] {Apple Croissant,                   
##        Apple Danish,                      
##        Apple Tart,                        
##        Cherry Soda}          0.02060   412
## [114] {Green Tea,                         
##        Lemon Lemonade,                    
##        Raspberry Cookie}     0.02040   408
## [115] {Green Tea,                         
##        Lemon Lemonade,                    
##        Raspberry Lemonade}   0.02030   406
## [116] {Green Tea,                         
##        Lemon Cookie,                      
##        Lemon Lemonade}       0.02030   406
## [117] {Green Tea,                         
##        Lemon Cookie,                      
##        Raspberry Lemonade}   0.02030   406
## [118] {Green Tea,                         
##        Raspberry Cookie,                  
##        Raspberry Lemonade}   0.02025   405
## [119] {Green Tea,                         
##        Lemon Cookie,                      
##        Raspberry Cookie}     0.02025   405
## [120] {Green Tea,                         
##        Lemon Cookie,                      
##        Lemon Lemonade,                    
##        Raspberry Lemonade}   0.02020   404
## [121] {Green Tea,                         
##        Lemon Lemonade,                    
##        Raspberry Cookie,                  
##        Raspberry Lemonade}   0.02020   404
## [122] {Green Tea,                         
##        Lemon Cookie,                      
##        Lemon Lemonade,                    
##        Raspberry Cookie}     0.02015   403
## [123] {Green Tea,                         
##        Lemon Cookie,                      
##        Raspberry Cookie,                  
##        Raspberry Lemonade}   0.02015   403
## [124] {Green Tea,                         
##        Lemon Cookie,                      
##        Lemon Lemonade,                    
##        Raspberry Cookie,                  
##        Raspberry Lemonade}   0.02015   403
rules3 <- apriori(transact3, parameter=list(support = 0.019, confidence=0.94))#, confidence = 0.6
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##        0.94    0.1    1 none FALSE            TRUE       5   0.019      1
##  maxlen target  ext
##      10  rules TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 380 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[50 item(s), 20000 transaction(s)] done [0.01s].
## sorting and recoding items ... [50 item(s)] done [0.00s].
## creating transaction tree ... done [0.01s].
## checking subsets of size 1 2 3 4 5 done [0.00s].
## writing ... [32 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
summary(rules3)
## set of 32 rules
## 
## rule length distribution (lhs + rhs):sizes
##  3  4  5 
##  6 22  4 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   3.000   4.000   4.000   3.938   4.000   5.000 
## 
## summary of quality measures:
##     support          confidence        coverage            lift       
##  Min.   :0.02015   Min.   :0.9433   Min.   :0.02015   Min.   : 8.659  
##  1st Qu.:0.02015   1st Qu.:0.9917   1st Qu.:0.02029   1st Qu.:13.979  
##  Median :0.02040   Median :0.9951   Median :0.02053   Median :14.423  
##  Mean   :0.02384   Mean   :0.9872   Mean   :0.02424   Mean   :13.869  
##  3rd Qu.:0.02548   3rd Qu.:0.9967   3rd Qu.:0.02660   3rd Qu.:14.698  
##  Max.   :0.04090   Max.   :1.0000   Max.   :0.04320   Max.   :15.140  
##      count      
##  Min.   :403.0  
##  1st Qu.:403.0  
##  Median :408.0  
##  Mean   :476.9  
##  3rd Qu.:509.5  
##  Max.   :818.0  
## 
## mining info:
##       data ntransactions support confidence
##  transact3         20000   0.019       0.94
##                                                                             call
##  apriori(data = transact3, parameter = list(support = 0.019, confidence = 0.94))
#inspect(rules3, by="confidence")
inspect(rules3, by="lift")
##      lhs                     rhs                  support confidence coverage      lift count
## [1]  {Lemon Lemonade,                                                                        
##       Raspberry Lemonade} => {Lemon Cookie}       0.02545  0.9567669  0.02660 14.028840   509
## [2]  {Lemon Lemonade,                                                                        
##       Raspberry Lemonade} => {Raspberry Cookie}   0.02555  0.9605263  0.02660 13.830473   511
## [3]  {Casino Cake,                                                                           
##       Chocolate Coffee}   => {Chocolate Cake}     0.03345  0.9543509  0.03505 11.408857   669
## [4]  {Almond Twist,                                                                          
##       Apple Pie}          => {Coffee Eclair}      0.03410  0.9511855  0.03585  8.658949   682
## [5]  {Almond Twist,                                                                          
##       Coffee Eclair}      => {Apple Pie}          0.03410  0.9432918  0.03615 12.721400   682
## [6]  {Apricot Danish,                                                                        
##       Opera Cake}         => {Cherry Tart}        0.04090  0.9467593  0.04320 10.375444   818
## [7]  {Apple Danish,                                                                          
##       Apple Tart,                                                                            
##       Cherry Soda}        => {Apple Croissant}    0.02060  0.9975787  0.02065 14.080151   412
## [8]  {Apple Croissant,                                                                       
##       Apple Danish,                                                                          
##       Cherry Soda}        => {Apple Tart}         0.02060  0.9927711  0.02075 14.336045   412
## [9]  {Apple Croissant,                                                                       
##       Apple Tart,                                                                            
##       Cherry Soda}        => {Apple Danish}       0.02060  0.9951691  0.02070 14.743246   412
## [10] {Green Tea,                                                                             
##       Lemon Lemonade,                                                                        
##       Raspberry Lemonade} => {Lemon Cookie}       0.02020  0.9950739  0.02030 14.590526   404
## [11] {Green Tea,                                                                             
##       Lemon Cookie,                                                                          
##       Lemon Lemonade}     => {Raspberry Lemonade} 0.02020  0.9950739  0.02030 14.698285   404
## [12] {Green Tea,                                                                             
##       Lemon Cookie,                                                                          
##       Raspberry Lemonade} => {Lemon Lemonade}     0.02020  0.9950739  0.02030 15.065464   404
## [13] {Green Tea,                                                                             
##       Lemon Lemonade,                                                                        
##       Raspberry Lemonade} => {Raspberry Cookie}   0.02020  0.9950739  0.02030 14.327918   404
## [14] {Green Tea,                                                                             
##       Lemon Lemonade,                                                                        
##       Raspberry Cookie}   => {Raspberry Lemonade} 0.02020  0.9901961  0.02040 14.626235   404
## [15] {Green Tea,                                                                             
##       Raspberry Cookie,                                                                      
##       Raspberry Lemonade} => {Lemon Lemonade}     0.02020  0.9975309  0.02025 15.102663   404
## [16] {Green Tea,                                                                             
##       Lemon Cookie,                                                                          
##       Lemon Lemonade}     => {Raspberry Cookie}   0.02015  0.9926108  0.02030 14.292453   403
## [17] {Green Tea,                                                                             
##       Lemon Lemonade,                                                                        
##       Raspberry Cookie}   => {Lemon Cookie}       0.02015  0.9877451  0.02040 14.483066   403
## [18] {Green Tea,                                                                             
##       Lemon Cookie,                                                                          
##       Raspberry Cookie}   => {Lemon Lemonade}     0.02015  0.9950617  0.02025 15.065280   403
## [19] {Green Tea,                                                                             
##       Lemon Cookie,                                                                          
##       Raspberry Lemonade} => {Raspberry Cookie}   0.02015  0.9926108  0.02030 14.292453   403
## [20] {Green Tea,                                                                             
##       Raspberry Cookie,                                                                      
##       Raspberry Lemonade} => {Lemon Cookie}       0.02015  0.9950617  0.02025 14.590348   403
## [21] {Green Tea,                                                                             
##       Lemon Cookie,                                                                          
##       Raspberry Cookie}   => {Raspberry Lemonade} 0.02015  0.9950617  0.02025 14.698105   403
## [22] {Lemon Cookie,                                                                          
##       Lemon Lemonade,                                                                        
##       Raspberry Lemonade} => {Raspberry Cookie}   0.02535  0.9960707  0.02545 14.342271   507
## [23] {Lemon Lemonade,                                                                        
##       Raspberry Cookie,                                                                      
##       Raspberry Lemonade} => {Lemon Cookie}       0.02535  0.9921722  0.02555 14.547980   507
## [24] {Lemon Cookie,                                                                          
##       Lemon Lemonade,                                                                        
##       Raspberry Cookie}   => {Raspberry Lemonade} 0.02535  0.9921722  0.02555 14.655424   507
## [25] {Lemon Cookie,                                                                          
##       Raspberry Cookie,                                                                      
##       Raspberry Lemonade} => {Lemon Lemonade}     0.02535  0.9941176  0.02550 15.050986   507
## [26] {Almond Twist,                                                                          
##       Apple Pie,                                                                             
##       Hot Coffee}         => {Coffee Eclair}      0.02785  0.9964222  0.02795  9.070753   557
## [27] {Almond Twist,                                                                          
##       Coffee Eclair,                                                                         
##       Hot Coffee}         => {Apple Pie}          0.02785  1.0000000  0.02785 13.486177   557
## [28] {Apple Pie,                                                                             
##       Coffee Eclair,                                                                         
##       Hot Coffee}         => {Almond Twist}       0.02785  1.0000000  0.02785 13.745704   557
## [29] {Green Tea,                                                                             
##       Lemon Cookie,                                                                          
##       Lemon Lemonade,                                                                        
##       Raspberry Lemonade} => {Raspberry Cookie}   0.02015  0.9975248  0.02020 14.363207   403
## [30] {Green Tea,                                                                             
##       Lemon Lemonade,                                                                        
##       Raspberry Cookie,                                                                      
##       Raspberry Lemonade} => {Lemon Cookie}       0.02015  0.9975248  0.02020 14.626463   403
## [31] {Green Tea,                                                                             
##       Lemon Cookie,                                                                          
##       Lemon Lemonade,                                                                        
##       Raspberry Cookie}   => {Raspberry Lemonade} 0.02015  1.0000000  0.02015 14.771049   403
## [32] {Green Tea,                                                                             
##       Lemon Cookie,                                                                          
##       Raspberry Cookie,                                                                      
##       Raspberry Lemonade} => {Lemon Lemonade}     0.02015  1.0000000  0.02015 15.140045   403
plot(rules3, engine="htmlwidget", main="20K data Lift on Confidence vs Support")
## To reduce overplotting, jitter is added! Use jitter = 0 to prevent jitter.

iv - Applying Apriori - 75K

#minSup, minConf

frequent_list4 <- apriori(transact4, parameter=list(support = 0.019, target="frequent itemsets"))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##          NA    0.1    1 none FALSE            TRUE       5   0.019      1
##  maxlen            target  ext
##      10 frequent itemsets TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 1425 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[50 item(s), 75000 transaction(s)] done [0.03s].
## sorting and recoding items ... [50 item(s)] done [0.00s].
## creating transaction tree ... done [0.07s].
## checking subsets of size 1 2 3 4 5 done [0.01s].
## sorting transactions ... done [0.03s].
## writing ... [124 set(s)] done [0.00s].
## creating S4 object  ... done [0.02s].
inspect(sort(frequent_list4, decreasing = T, by="support"))
##       items                     support count
## [1]   {Coffee Eclair}        0.10924000  8193
## [2]   {Tuile Cookie}         0.10069333  7552
## [3]   {Hot Coffee}           0.10068000  7551
## [4]   {Cherry Tart}          0.09316000  6987
## [5]   {Strawberry Cake}      0.09264000  6948
## [6]   {Apricot Danish}       0.09226667  6920
## [7]   {Orange Juice}         0.09061333  6796
## [8]   {Gongolais Cookie}     0.09044000  6783
## [9]   {Marzipan Cookie}      0.08973333  6730
## [10]  {Berry Tart}           0.08482667  6362
## [11]  {Apricot Croissant}    0.08390667  6293
## [12]  {Lemon Cake}           0.08361333  6271
## [13]  {Chocolate Cake}       0.08353333  6265
## [14]  {Blueberry Tart}       0.08294667  6221
## [15]  {Napoleon Cake}        0.08274667  6206
## [16]  {Truffle Cake}         0.08224000  6168
## [17]  {Opera Cake}           0.08209333  6157
## [18]  {Cheese Croissant}     0.08197333  6148
## [19]  {Chocolate Coffee}     0.08106667  6080
## [20]  {Apple Pie}            0.07712000  5784
## [21]  {Almond Twist}         0.07686667  5765
## [22]  {Blackberry Tart}      0.07586667  5690
## [23]  {Lemon Tart}           0.07580000  5685
## [24]  {Casino Cake}          0.07501333  5626
## [25]  {Vanilla Frappuccino}  0.07461333  5596
## [26]  {Bottled Water}        0.07394667  5546
## [27]  {Chocolate Tart}       0.07372000  5529
## [28]  {Apple Tart}           0.06822667  5117
## [29]  {Lemon Cookie}         0.06801333  5101
## [30]  {Walnut Cookie}        0.06781333  5086
## [31]  {Lemon Lemonade}       0.06766667  5075
## [32]  {Raspberry Cookie}     0.06764000  5073
## [33]  {Apple Danish}         0.06742667  5057
## [34]  {Apple Croissant}      0.06721333  5041
## [35]  {Raspberry Lemonade}   0.06700000  5025
## [36]  {Single Espresso}      0.06473333  4855
## [37]  {Green Tea}            0.06144000  4608
## [38]  {Cherry Soda}          0.05957333  4468
## [39]  {Apricot Danish,                       
##        Cherry Tart}          0.05300000  3975
## [40]  {Marzipan Cookie,                      
##        Tuile Cookie}         0.05089333  3817
## [41]  {Gongolais Cookie,                     
##        Truffle Cake}         0.04392000  3294
## [42]  {Blueberry Danish}     0.04361333  3271
## [43]  {Apricot Croissant,                    
##        Blueberry Tart}       0.04349333  3262
## [44]  {Pecan Tart}           0.04337333  3253
## [45]  {Cherry Tart,                          
##        Opera Cake}           0.04337333  3253
## [46]  {Ganache Cookie}       0.04324000  3243
## [47]  {Chocolate Cake,                       
##        Chocolate Coffee}     0.04322667  3242
## [48]  {Napoleon Cake,                        
##        Strawberry Cake}      0.04314667  3236
## [49]  {Chocolate Croissant}  0.04310667  3233
## [50]  {Apricot Danish,                       
##        Opera Cake}           0.04292000  3219
## [51]  {Almond Croissant}     0.04265333  3199
## [52]  {Cheese Croissant,                     
##        Orange Juice}         0.04264000  3198
## [53]  {Vanilla Eclair}       0.04252000  3189
## [54]  {Chocolate Eclair}     0.04237333  3178
## [55]  {Vanilla Meringue}     0.04236000  3177
## [56]  {Apricot Tart}         0.04236000  3177
## [57]  {Almond Bear Claw}     0.04205333  3154
## [58]  {Almond Tart}          0.04204000  3153
## [59]  {Chocolate Meringue}   0.04190667  3143
## [60]  {Apricot Danish,                       
##        Cherry Tart,                          
##        Opera Cake}           0.04105333  3079
## [61]  {Berry Tart,                           
##        Bottled Water}        0.03733333  2800
## [62]  {Apple Pie,                            
##        Coffee Eclair}        0.03726667  2795
## [63]  {Almond Twist,                         
##        Coffee Eclair}        0.03702667  2777
## [64]  {Lemon Cake,                           
##        Lemon Tart}           0.03685333  2764
## [65]  {Almond Twist,                         
##        Apple Pie}            0.03657333  2743
## [66]  {Blackberry Tart,                      
##        Coffee Eclair}        0.03641333  2731
## [67]  {Casino Cake,                          
##        Chocolate Cake}       0.03553333  2665
## [68]  {Chocolate Tart,                       
##        Vanilla Frappuccino}  0.03500000  2625
## [69]  {Apricot Croissant,                    
##        Hot Coffee}           0.03485333  2614
## [70]  {Casino Cake,                          
##        Chocolate Coffee}     0.03461333  2596
## [71]  {Blueberry Tart,                       
##        Hot Coffee}           0.03450667  2588
## [72]  {Almond Twist,                         
##        Apple Pie,                            
##        Coffee Eclair}        0.03428000  2571
## [73]  {Casino Cake,                          
##        Chocolate Cake,                       
##        Chocolate Coffee}     0.03293333  2470
## [74]  {Apricot Croissant,                    
##        Blueberry Tart,                       
##        Hot Coffee}           0.03244000  2433
## [75]  {Coffee Eclair,                        
##        Hot Coffee}           0.03102667  2327
## [76]  {Apple Pie,                            
##        Hot Coffee}           0.03050667  2288
## [77]  {Almond Twist,                         
##        Hot Coffee}           0.03037333  2278
## [78]  {Blackberry Tart,                      
##        Single Espresso}      0.02864000  2148
## [79]  {Coffee Eclair,                        
##        Single Espresso}      0.02856000  2142
## [80]  {Chocolate Tart,                       
##        Walnut Cookie}        0.02854667  2141
## [81]  {Vanilla Frappuccino,                  
##        Walnut Cookie}        0.02788000  2091
## [82]  {Lemon Lemonade,                       
##        Raspberry Cookie}     0.02786667  2090
## [83]  {Lemon Cookie,                         
##        Raspberry Cookie}     0.02782667  2087
## [84]  {Apple Croissant,                      
##        Apple Danish}         0.02780000  2085
## [85]  {Apple Croissant,                      
##        Apple Tart}           0.02780000  2085
## [86]  {Apple Danish,                         
##        Apple Tart}           0.02780000  2085
## [87]  {Almond Twist,                         
##        Coffee Eclair,                        
##        Hot Coffee}           0.02780000  2085
## [88]  {Apple Pie,                            
##        Coffee Eclair,                        
##        Hot Coffee}           0.02778667  2084
## [89]  {Lemon Cookie,                         
##        Raspberry Lemonade}   0.02772000  2079
## [90]  {Lemon Lemonade,                       
##        Raspberry Lemonade}   0.02770667  2078
## [91]  {Lemon Cookie,                         
##        Lemon Lemonade}       0.02770667  2078
## [92]  {Almond Twist,                         
##        Apple Pie,                            
##        Hot Coffee}           0.02770667  2078
## [93]  {Almond Twist,                         
##        Apple Pie,                            
##        Coffee Eclair,                        
##        Hot Coffee}           0.02761333  2071
## [94]  {Raspberry Cookie,                     
##        Raspberry Lemonade}   0.02758667  2069
## [95]  {Blackberry Tart,                      
##        Coffee Eclair,                        
##        Single Espresso}      0.02662667  1997
## [96]  {Chocolate Tart,                       
##        Vanilla Frappuccino,                  
##        Walnut Cookie}        0.02625333  1969
## [97]  {Lemon Cookie,                         
##        Lemon Lemonade,                       
##        Raspberry Cookie}     0.02573333  1930
## [98]  {Lemon Lemonade,                       
##        Raspberry Cookie,                     
##        Raspberry Lemonade}   0.02568000  1926
## [99]  {Lemon Cookie,                         
##        Raspberry Cookie,                     
##        Raspberry Lemonade}   0.02562667  1922
## [100] {Lemon Cookie,                         
##        Lemon Lemonade,                       
##        Raspberry Lemonade}   0.02558667  1919
## [101] {Lemon Cookie,                         
##        Lemon Lemonade,                       
##        Raspberry Cookie,                     
##        Raspberry Lemonade}   0.02552000  1914
## [102] {Apple Croissant,                      
##        Apple Danish,                         
##        Apple Tart}           0.02546667  1910
## [103] {Green Tea,                            
##        Lemon Cookie}         0.02276000  1707
## [104] {Green Tea,                            
##        Raspberry Cookie}     0.02273333  1705
## [105] {Green Tea,                            
##        Lemon Lemonade}       0.02262667  1697
## [106] {Apple Danish,                         
##        Cherry Soda}          0.02257333  1693
## [107] {Green Tea,                            
##        Raspberry Lemonade}   0.02256000  1692
## [108] {Apple Croissant,                      
##        Cherry Soda}          0.02230667  1673
## [109] {Apple Tart,                           
##        Cherry Soda}          0.02218667  1664
## [110] {Green Tea,                            
##        Lemon Cookie,                         
##        Raspberry Lemonade}   0.02065333  1549
## [111] {Green Tea,                            
##        Lemon Cookie,                         
##        Lemon Lemonade}       0.02060000  1545
## [112] {Green Tea,                            
##        Raspberry Cookie,                     
##        Raspberry Lemonade}   0.02058667  1544
## [113] {Green Tea,                            
##        Lemon Lemonade,                       
##        Raspberry Cookie}     0.02056000  1542
## [114] {Green Tea,                            
##        Lemon Lemonade,                       
##        Raspberry Lemonade}   0.02053333  1540
## [115] {Green Tea,                            
##        Lemon Cookie,                         
##        Raspberry Cookie}     0.02052000  1539
## [116] {Green Tea,                            
##        Lemon Lemonade,                       
##        Raspberry Cookie,                     
##        Raspberry Lemonade}   0.02048000  1536
## [117] {Green Tea,                            
##        Lemon Cookie,                         
##        Lemon Lemonade,                       
##        Raspberry Lemonade}   0.02048000  1536
## [118] {Green Tea,                            
##        Lemon Cookie,                         
##        Raspberry Cookie,                     
##        Raspberry Lemonade}   0.02048000  1536
## [119] {Green Tea,                            
##        Lemon Cookie,                         
##        Lemon Lemonade,                       
##        Raspberry Cookie}     0.02048000  1536
## [120] {Green Tea,                            
##        Lemon Cookie,                         
##        Lemon Lemonade,                       
##        Raspberry Cookie,                     
##        Raspberry Lemonade}   0.02048000  1536
## [121] {Apple Croissant,                      
##        Apple Danish,                         
##        Cherry Soda}          0.02042667  1532
## [122] {Apple Croissant,                      
##        Apple Tart,                           
##        Cherry Soda}          0.02041333  1531
## [123] {Apple Danish,                         
##        Apple Tart,                           
##        Cherry Soda}          0.02040000  1530
## [124] {Apple Croissant,                      
##        Apple Danish,                         
##        Apple Tart,                           
##        Cherry Soda}          0.02025333  1519
rules4 <- apriori(transact4, parameter=list(support = 0.019, confidence=0.94))#, confidence = 0.6
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##        0.94    0.1    1 none FALSE            TRUE       5   0.019      1
##  maxlen target  ext
##      10  rules TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 1425 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[50 item(s), 75000 transaction(s)] done [0.03s].
## sorting and recoding items ... [50 item(s)] done [0.00s].
## creating transaction tree ... done [0.03s].
## checking subsets of size 1 2 3 4 5 done [0.01s].
## writing ... [31 rule(s)] done [0.00s].
## creating S4 object  ... done [0.01s].
summary(rules4)
## set of 31 rules
## 
## rule length distribution (lhs + rhs):sizes
##  3  4  5 
##  5 22  4 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   3.000   4.000   4.000   3.968   4.000   5.000 
## 
## summary of quality measures:
##     support          confidence        coverage            lift       
##  Min.   :0.02025   Min.   :0.9401   Min.   :0.02040   Min.   : 9.123  
##  1st Qu.:0.02048   1st Qu.:0.9917   1st Qu.:0.02052   1st Qu.:13.731  
##  Median :0.02048   Median :0.9942   Median :0.02060   Median :14.698  
##  Mean   :0.02410   Mean   :0.9877   Mean   :0.02449   Mean   :13.860  
##  3rd Qu.:0.02589   3rd Qu.:0.9974   3rd Qu.:0.02672   3rd Qu.:14.760  
##  Max.   :0.04105   Max.   :1.0000   Max.   :0.04337   Max.   :14.925  
##      count     
##  Min.   :1519  
##  1st Qu.:1536  
##  Median :1536  
##  Mean   :1807  
##  3rd Qu.:1942  
##  Max.   :3079  
## 
## mining info:
##       data ntransactions support confidence
##  transact4         75000   0.019       0.94
##                                                                             call
##  apriori(data = transact4, parameter = list(support = 0.019, confidence = 0.94))
#inspect(rules4, by="confidence")
inspect(rules4, by="lift")
##      lhs                       rhs                     support confidence   coverage      lift count
## [1]  {Vanilla Frappuccino,                                                                          
##       Walnut Cookie}        => {Chocolate Tart}     0.02625333  0.9416547 0.02788000 12.773395  1969
## [2]  {Casino Cake,                                                                                  
##       Chocolate Coffee}     => {Chocolate Cake}     0.03293333  0.9514638 0.03461333 11.390229  2470
## [3]  {Blueberry Tart,                                                                               
##       Hot Coffee}           => {Apricot Croissant}  0.03244000  0.9401082 0.03450667 11.204213  2433
## [4]  {Apricot Danish,                                                                               
##       Opera Cake}           => {Cherry Tart}        0.04105333  0.9565082 0.04292000 10.267370  3079
## [5]  {Cherry Tart,                                                                                  
##       Opera Cake}           => {Apricot Danish}     0.04105333  0.9465109 0.04337333 10.258428  3079
## [6]  {Apple Croissant,                                                                              
##       Apple Danish,                                                                                 
##       Cherry Soda}          => {Apple Tart}         0.02025333  0.9915144 0.02042667 14.532651  1519
## [7]  {Apple Croissant,                                                                              
##       Apple Tart,                                                                                   
##       Cherry Soda}          => {Apple Danish}       0.02025333  0.9921620 0.02041333 14.714682  1519
## [8]  {Apple Danish,                                                                                 
##       Apple Tart,                                                                                   
##       Cherry Soda}          => {Apple Croissant}    0.02025333  0.9928105 0.02040000 14.771034  1519
## [9]  {Green Tea,                                                                                    
##       Lemon Lemonade,                                                                               
##       Raspberry Lemonade}   => {Raspberry Cookie}   0.02048000  0.9974026 0.02053333 14.745751  1536
## [10] {Green Tea,                                                                                    
##       Raspberry Cookie,                                                                             
##       Raspberry Lemonade}   => {Lemon Lemonade}     0.02048000  0.9948187 0.02058667 14.701753  1536
## [11] {Green Tea,                                                                                    
##       Lemon Lemonade,                                                                               
##       Raspberry Cookie}     => {Raspberry Lemonade} 0.02048000  0.9961089 0.02056000 14.867298  1536
## [12] {Green Tea,                                                                                    
##       Lemon Lemonade,                                                                               
##       Raspberry Lemonade}   => {Lemon Cookie}       0.02048000  0.9974026 0.02053333 14.664810  1536
## [13] {Green Tea,                                                                                    
##       Lemon Cookie,                                                                                 
##       Raspberry Lemonade}   => {Lemon Lemonade}     0.02048000  0.9916075 0.02065333 14.654298  1536
## [14] {Green Tea,                                                                                    
##       Lemon Cookie,                                                                                 
##       Lemon Lemonade}       => {Raspberry Lemonade} 0.02048000  0.9941748 0.02060000 14.838429  1536
## [15] {Green Tea,                                                                                    
##       Raspberry Cookie,                                                                             
##       Raspberry Lemonade}   => {Lemon Cookie}       0.02048000  0.9948187 0.02058667 14.626818  1536
## [16] {Green Tea,                                                                                    
##       Lemon Cookie,                                                                                 
##       Raspberry Lemonade}   => {Raspberry Cookie}   0.02048000  0.9916075 0.02065333 14.660075  1536
## [17] {Green Tea,                                                                                    
##       Lemon Cookie,                                                                                 
##       Raspberry Cookie}     => {Raspberry Lemonade} 0.02048000  0.9980507 0.02052000 14.896279  1536
## [18] {Green Tea,                                                                                    
##       Lemon Lemonade,                                                                               
##       Raspberry Cookie}     => {Lemon Cookie}       0.02048000  0.9961089 0.02056000 14.645789  1536
## [19] {Green Tea,                                                                                    
##       Lemon Cookie,                                                                                 
##       Lemon Lemonade}       => {Raspberry Cookie}   0.02048000  0.9941748 0.02060000 14.698030  1536
## [20] {Green Tea,                                                                                    
##       Lemon Cookie,                                                                                 
##       Raspberry Cookie}     => {Lemon Lemonade}     0.02048000  0.9980507 0.02052000 14.749517  1536
## [21] {Lemon Lemonade,                                                                               
##       Raspberry Cookie,                                                                             
##       Raspberry Lemonade}   => {Lemon Cookie}       0.02552000  0.9937695 0.02568000 14.611392  1914
## [22] {Lemon Cookie,                                                                                 
##       Lemon Lemonade,                                                                               
##       Raspberry Lemonade}   => {Raspberry Cookie}   0.02552000  0.9973945 0.02558667 14.745631  1914
## [23] {Lemon Cookie,                                                                                 
##       Raspberry Cookie,                                                                             
##       Raspberry Lemonade}   => {Lemon Lemonade}     0.02552000  0.9958377 0.02562667 14.716813  1914
## [24] {Lemon Cookie,                                                                                 
##       Lemon Lemonade,                                                                               
##       Raspberry Cookie}     => {Raspberry Lemonade} 0.02552000  0.9917098 0.02573333 14.801639  1914
## [25] {Almond Twist,                                                                                 
##       Apple Pie,                                                                                    
##       Hot Coffee}           => {Coffee Eclair}      0.02761333  0.9966314 0.02770667  9.123319  2071
## [26] {Almond Twist,                                                                                 
##       Coffee Eclair,                                                                                
##       Hot Coffee}           => {Apple Pie}          0.02761333  0.9932854 0.02780000 12.879738  2071
## [27] {Apple Pie,                                                                                    
##       Coffee Eclair,                                                                                
##       Hot Coffee}           => {Almond Twist}       0.02761333  0.9937620 0.02778667 12.928387  2071
## [28] {Green Tea,                                                                                    
##       Lemon Lemonade,                                                                               
##       Raspberry Cookie,                                                                             
##       Raspberry Lemonade}   => {Lemon Cookie}       0.02048000  1.0000000 0.02048000 14.702999  1536
## [29] {Green Tea,                                                                                    
##       Lemon Cookie,                                                                                 
##       Lemon Lemonade,                                                                               
##       Raspberry Lemonade}   => {Raspberry Cookie}   0.02048000  1.0000000 0.02048000 14.784151  1536
## [30] {Green Tea,                                                                                    
##       Lemon Cookie,                                                                                 
##       Raspberry Cookie,                                                                             
##       Raspberry Lemonade}   => {Lemon Lemonade}     0.02048000  1.0000000 0.02048000 14.778325  1536
## [31] {Green Tea,                                                                                    
##       Lemon Cookie,                                                                                 
##       Lemon Lemonade,                                                                               
##       Raspberry Cookie}     => {Raspberry Lemonade} 0.02048000  1.0000000 0.02048000 14.925373  1536
plot(rules4, engine="htmlwidget", main="75K data Lift on Confidence vs Support")
## To reduce overplotting, jitter is added! Use jitter = 0 to prevent jitter.

C - Comparing the Results

paste("1K: 121 frequent itemsets, 47 rules.
      5K: 124 frequent itemsets, 42 rules.
      20K: 124 frequent itemsets, 32 rules.
      75K: 124 frequent itemsets, 31 rules.
      Taking minSup=0.019 gives us a frequent itemlist of 121-124 in all transaction lists (1K,5K,20K,75K), with little change. However, the amount of rules we have decreases as we increase the size of our data from 1K to 75K. Therefore, as our data increase in size, we are more certain about the rules.")
## [1] "1K: 121 frequent itemsets, 47 rules.\n      5K: 124 frequent itemsets, 42 rules.\n      20K: 124 frequent itemsets, 32 rules.\n      75K: 124 frequent itemsets, 31 rules.\n      Taking minSup=0.019 gives us a frequent itemlist of 121-124 in all transaction lists (1K,5K,20K,75K), with little change. However, the amount of rules we have decreases as we increase the size of our data from 1K to 75K. Therefore, as our data increase in size, we are more certain about the rules."

D - Most-Least Frequent Item(set)

frequent_list4 <- apriori(transact4, parameter=list(support = 0.019, target="frequent itemsets")) #0.05
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##          NA    0.1    1 none FALSE            TRUE       5   0.019      1
##  maxlen            target  ext
##      10 frequent itemsets TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 1425 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[50 item(s), 75000 transaction(s)] done [0.02s].
## sorting and recoding items ... [50 item(s)] done [0.00s].
## creating transaction tree ... done [0.06s].
## checking subsets of size 1 2 3 4 5 done [0.01s].
## sorting transactions ... done [0.03s].
## writing ... [124 set(s)] done [0.00s].
## creating S4 object  ... done [0.02s].
inspect(head(sort(frequent_list4, decreasing = T, by="support")))
##     items             support    count
## [1] {Coffee Eclair}   0.10924000 8193 
## [2] {Tuile Cookie}    0.10069333 7552 
## [3] {Hot Coffee}      0.10068000 7551 
## [4] {Cherry Tart}     0.09316000 6987 
## [5] {Strawberry Cake} 0.09264000 6948 
## [6] {Apricot Danish}  0.09226667 6920
inspect(head(sort(frequent_list4, decreasing = F, by="support")))
##     items                   support count
## [1] {Apple Croissant,                    
##      Apple Danish,                       
##      Apple Tart,                         
##      Cherry Soda}        0.02025333  1519
## [2] {Apple Danish,                       
##      Apple Tart,                         
##      Cherry Soda}        0.02040000  1530
## [3] {Apple Croissant,                    
##      Apple Tart,                         
##      Cherry Soda}        0.02041333  1531
## [4] {Apple Croissant,                    
##      Apple Danish,                       
##      Cherry Soda}        0.02042667  1532
## [5] {Green Tea,                          
##      Lemon Lemonade,                     
##      Raspberry Cookie,                   
##      Raspberry Lemonade} 0.02048000  1536
## [6] {Green Tea,                          
##      Lemon Cookie,                       
##      Lemon Lemonade,                     
##      Raspberry Lemonade} 0.02048000  1536
paste("The most frequent item is Coffee Eclair, with a support of 0.11, counted 8193 times. The least frequent itemset is: {Apple Croissant, Apple Danish, Apple Tart, Cherry Soda} with a support of 0.02, counted 1519 times.")
## [1] "The most frequent item is Coffee Eclair, with a support of 0.11, counted 8193 times. The least frequent itemset is: {Apple Croissant, Apple Danish, Apple Tart, Cherry Soda} with a support of 0.02, counted 1519 times."

2.2 - Recommender System - Incomplete

#movies_original <- read.csv("/Users/aliguzelyel/Desktop/Classes-College/CS/CS\ 422/Homework\ 9\ CS\ 422/ml-latest-small/movies.csv", sep=",", header=T)
#head(movies_original)
#ratings <- read.csv("/Users/aliguzelyel/Desktop/Classes-College/CS/CS\ 422/Homework\ 9\ CS\ 422/ml-latest-small/ratings.csv")
#head(ratings)
#user_w_mov <- data.frame(1, as.data.frame(t(ratings$movieId[which(ratings$userId==1)])))
#user_w_mov <- rbind.fill(user_w_mov, data.frame(as.data.frame(t(c(ratings$movieId[which(ratings$userId==2)])))))
#user_w_mov
#head(user_w_mov)
#for (i in 2:671){
#  user_w_mov <- rbind.fill(user_w_mov, as.data.frame(t(ratings$movieId[which(ratings$userId==i)])))
#  #user_w_mov
#  #df = rbind(df, data.frame(x,y,z))
#}
#user_w_mov
#user_w_mov$X1 <- c(1:671)
#user_w_mov
#as.data.frame(t(user_w_mov))